const cartStore = {
    state: {
        cartList:[]
    },
    mutations: {
        ADD_CART(state,goods){
            // let rel = false 
            // state.cartList.forEach((item)=>{
            //     if(goods.id == item.goods.id){
            //         rel = true
            //         item.num ++
            //     }
            // })
            // if(rel==false){
            //     state.cartList.push({
            //         goods,
            //         num:2
            //     })
            // }
            // console.log(state.cartList)

            console.log(goods)

             let rel = true 
            state.cartList.forEach((item)=>{
                if(goods.goods.id == item.goods.id){
                   if(item.guige == goods.guige){
                    rel = false
                    item.num = item.num + goods.num
                   }
                }
            })
          
            if(rel){
                state.cartList.push(goods)
            }
            console.log(state.cartList)
        },
        DEL(state,index){
            state.cartList.splice(index,1)
        }
    },
    actions: {
        ADD_CART(context,obj){
            context.commit("ADD_CART",obj)
        },
        DEL(context,index){
            context.commit("DEL",index)
        }
    },
}
export default cartStore